const initField = function(ui) {
	const obj = {
		'element': {
			label: 'label',
			prop: 'prop'
		},
		'iview': {
			label: 'title',
			prop: 'slot'
		}
	}
	return obj[ui];
}

const getIcon = function(elementIcon, iviewIcon, ui) {
	if (ui === 'element') {
		return {
			icon: elementIcon
		}
	} else {
		return {
			attrs: {
				icon: iviewIcon,
				shape: 'circle'
			}
		}
	}
}
//列表表头配置
export default {
	main(tree) {
		const { prop, label } = initField(this.ui);
		const area = tree.initArea()
		return [{
				type: 'expand',
				width: 50,
				render: (h) => {
					return h('span', {
						domProps: {
							innerText: 'JIESS'
						}
					})
				}
			},
			{
				type: 'selection',
				width: 55,
			}, {
				[label]: '序号',
				width: 65,
				type: 'index',
				// indexMethod: props => props.$index + 1
			}, {
				[label]: '姓名',
				[prop]: 'name',
			},
			{
				[label]: '性别',
				[prop]: 'sex',
				sortable: 'custom',
				//兼容iview环境,在element环境下，可以用render
				JRender: () => area.jsRadioGroup({
					name: 'sex',
					groups: [{
						[label]: '男',
						value: 1,
					}, {
						[label]: '女',
						value: 2,
					}]
				})
			},
			{
				[label]: '出生时间',
				[prop]: 'birth',
				//兼容iview环境,在element环境下，可以用render
				JRender: () => area.jsDate({
					name: 'birth',
					type: "date",
				})
			},
			{
				[label]: '是否报名',
				[prop]: 'isAdult',
				//兼容iview环境,在element环境下，可以用render
				JRender: () => area.jsSwitch({
					name: 'isAdult'
				})
			},
			{
				[label]: '家庭地址',
				[prop]: 'native',
			},
			{
				[label]: "操作",
				[prop]: 'action',
				width: "150",
				tools: {
					//点击会触发页面同名函数,即回调页面中名为detail的function
					edit: {
						tipText: "编辑男生信息",
						buttonText: '编辑男生',
						buttonTextAttrs: {
							style: {
								'font-size': '1rem',
							}
						},
						conditionDisabled: {
							field: 'isAdult',
							value: true
						},
						conditionChange: [{
							field: 'sex',
							value: 2,
							buttonText: '编辑女生',
							tipText: "编辑女生信息",
						}]
					},
					delete: {
						...getIcon('el-icon-delete', 'ios-trash', this.ui),
						type: "warning",
						tipText: "删除",
						conditionShow: {
							field: 'isAdult',
							value: false
						}
					}
				}
			}
		]
	}
}
